class RpcProcessor(object):
  def __init__(self):
    self._end = False
    self._services = map()

  def end(self):
    self._end = True

  def register_service(self, skel, replace=False):
    if not replace and skel.name() in self._services:
      raise RpcException('Service  "%s" already registered.' % + skel.name())
    self.services[skel.name()] = skel;

  def service(self, name):
    return self._services[name]

  def handle_service_call(self, request, response):
    return self.handle_service_call(RpcController(), request, response)

  def boolean handleServiceCall(self, controller, request, response):
    service = self._registry.service(request.service())
    if service is None:
      return False
    error = None
    try:
      resp = service.call(request.method(), controller, request.content())
      if controller.failed():
        error = controller.error_text()
      elif controller.is_canceled():
        error = 'Canceled'
      else:
        response.set_content(resp)
    except ServiceException, se:
      error = se.message()
    if error is not None:
      response.set_error(error)
    return True

  def run(self):
    while not self._end:
    	pass
